import axios from 'axios'
import qs from 'qs'

const instance = axios.create({
    baseURL: 'http://localhost:3001',
    timeout: 5000
})

instance.interceptors.request.use(config => {
    config.method == 'data' ? config.data = qs.stringify({ ...config.data }) : config.params = { ...config.params }
    return config
}, error => {
    return Promise.reject(error)
})

instance.interceptors.response.use(response => {
    return response.data
}, error => {
    return Promise.reject(error)
})

export default instance